package com.jdsm.controllers;

import com.jdsm.model.Browser;
import com.jdsm.services.BrowserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/browser")
public class BrowserController {

    @Autowired
    BrowserService browserService;

    @GetMapping("/showall")
    public String getBrowers(Model model) {
        List<Browser> browsers = browserService.findAll();
        model.addAttribute("browsers", browsers);
        return "/browser/all";
    }

    @GetMapping("/getall")
    @ResponseBody
    public List<Browser> getAllBrowsers() {
        return browserService.findAll();
    }
}
